package com.bootdo.oa.controller;

import com.bootdo.common.controller.BaseController;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.runtime.ProcessInstance;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @author ：mmzs
 * @date ：Created in 2020/12/17 0017 下午 5:20
 * @description：工作流引擎,采购流程
 * @modified By：
 * @version: 1.1$
 */

@Controller
@RequestMapping("/oa/purchase")
public class PurchaseController extends BaseController {

    ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();

    @GetMapping("/deployment")
    public void deployment() {
        Deployment deployment = processEngine.getRepositoryService()//与流程定义和部署相关的Service
                .createDeployment()//创建一个部署对象
                .name("helloword")//添加部署的名称
                .addClasspathResource("diagrams/helloword.bpmn")//从classpath下加载资源，一次一个
                .addClasspathResource("diagrams/helloword.png")
                .deploy();//完成部署
        System.out.println("部署ID"+deployment.getId());//1
        System.out.println("部署名称"+deployment.getName());
    }




    @GetMapping("/start")
    public void startProcessInstance() {
        String processDefinitionKey = "aaaa";
        ProcessInstance processInstance = processEngine.getRuntimeService()//与正在执行的流程实例和执行对象相关的Service
                .startProcessInstanceByKey(processDefinitionKey);//根据Key值来查询流程,也可以根据ID
        System.out.println("流程实例ID:"+processInstance.getId());  //2501
        //对应数据库act_ru_execution
        System.out.println("流程定义ID:"+processInstance.getProcessDefinitionId()); //helloword:1:4
        //对应数据库act_re_deployment
    }











}
